package com.enzoism.springboot.dive.chapter02;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author heian
 * @create 2020-01-08-2:18 下午
 * @description 测试类
 * @link https://blog.csdn.net/qq_40826106/article/details/88628536
 */
public class TestSingle {

    public static void task() throws InterruptedException {
        TimeUnit.SECONDS.sleep(3);
        System.out.println(Thread.currentThread().getName());
    }

    public static void main(String[] args) {
        ExecutorService executors = SingleThreadPool.getInstance().getExecutors();
        for (int i = 0; i < 10; i++) {
            executors.submit(() -> {
                try {
                    task();
                    System.out.println(executors.toString());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }

    }
}